<?php

if (!isset($segments[2]) || ($segments[2] < 1 || $segments[2] > 20)) {
    include APPPATH . '404.php';
    die();
}
$bookSql = 'SELECT `book_name` FROM `ryadus_salehin_books` WHERE `id`=\'' . $segments[2] . '\'';
$bookQ = $db->query($bookSql);
$bookName = $bookQ->fetchAll(PDO::FETCH_COLUMN, 0);
$title = $bookName[0];


$sql = 'SELECT * FROM  `ryadus_salehin`
    WHERE `book_id`=\'' . $segments[2] . '\'';
$query = $db->query($sql);

$results = $query->fetchAll(PDO::FETCH_ASSOC);

include './app/layout/header.php';
?>
<div class="section_w670">
    <h2><?php echo $title; ?></h2>
</div>
<div class="cleaner_h10"></div>
<div class="section_w670">
<?php
foreach ($results as $result) {
    //echo '<p><b>Narrated By: ' . $result['narrator_name'] . '</b></p>';
    //echo '<div class="cleaner_h10"></div>';
    echo '<b>Hadith Number: ' . $result['hadith_number'] . ' Chapter Number: ' . $result['chapter_id'] . '</b>';
    echo '<p>' . $result['full_text'] . '</p>';
    echo '<p><b>commentary:</b><br />';
    echo '' . $result['commentary'] . '</p>';
    echo '<div class="cleaner_h20"></div>';
}
?>
</div>
<div class="cleaner_h10"></div>
<?php
include './app/layout/footer.php';